using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class JobSeekers_coverletters : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session.Contents["jsuserid"] == null)
        {
            Response.Redirect("login.aspx");
        }
        else
        {
            if (!IsPostBack)
            {
                ShowCoverLetter();
            }
        }
    }
    void ShowCoverLetter()
    {
        SQLServerProviders cls = new SQLServerProviders();
        DataTable dataTable = cls.GetDataTable(
        "select LetterID,Subject, " +
        "Convert(char(10), CreateDate,103) as CreateDate ,"
        +"Convert(char(10), UpdateDate,103) as UpdateDate " +
        " from tblJSCoverLetters " +
        " where UserID='" + Convert.ToString(
        Session.Contents["jsuserid"])
        + "'", CommandType.Text);
        GridView1.DataSource = dataTable;
        GridView1.DataBind();
    }
    protected void btnNew_Click(object sender, EventArgs e)
    {
        Response.Redirect("coverletter.aspx");
    }
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        DeleteCoverLetter();
        ShowCoverLetter();
    }
    void DeleteCoverLetter()
    {
        string letterID = "";
        foreach (GridViewRow item in GridView1.Rows)
        {
            CheckBox checkBox = (CheckBox)item.Cells[0].FindControl("chkCoverLetterID");
            if (checkBox.Checked)
                letterID += item.Cells[0].Text + ",";
        }
        if (letterID != "")
        {
            SQLServerProviders cls = new SQLServerProviders();
            cls.ExecuteNonQuery(
            "delete  from tblJSCoverLetters " +
            " where UserID='" + Convert.ToString(
            Session.Contents["jsuserid"])
            + "' and LetterID in('" +
            letterID.Replace(",", "','") + "')",
            CommandType.Text);
        }
    }
}
